package edu.usc.csci578.project;

import edu.usc.csci578.project.generated.specified.Cluster;

/**
 * A pair of redundant components and the topic proportion distance between them
 */
public class RedundantComponentPair implements
		Comparable<RedundantComponentPair>
{
	/**
	 * First cluster of the pair
	 */
	private final Cluster cluster1;
	/**
	 * Second cluster of the pair
	 */
	private final Cluster cluster2;
	/**
	 * Topic proportion distance
	 */
	private final double distance;

	/**
	 * Constructor
	 * 
	 * @param cluster1
	 *            First cluster of the pair
	 * @param cluster2
	 *            Second cluster of the pair
	 * @param distance
	 *            topic proportion distance
	 */
	public RedundantComponentPair(final Cluster cluster1,
			final Cluster cluster2, final double distance)
	{
		this.cluster1 = cluster1;
		this.cluster2 = cluster2;
		this.distance = distance;
	}

	@Override
	public int compareTo(final RedundantComponentPair o)
	{
		final int distanceCompareTo = Double.compare(distance, o.distance);
		if (distanceCompareTo != 0)
			return distanceCompareTo;
		final int cluster1CompareTo = cluster1.getName().compareTo(
				o.getFirst().getName());
		if (cluster1CompareTo != 0)
			return cluster1CompareTo;
		return cluster2.getName().compareTo(o.getSecond().getName());
	}

	/**
	 * Getter for the topic proportion distance
	 * 
	 * @return the topic proportion distance between the two clusters
	 */
	public double getDistance()
	{
		return distance;
	}

	/**
	 * Getter for the first cluster of the pair
	 * 
	 * @return the first cluster of the pair
	 */
	public Cluster getFirst()
	{
		return cluster1;
	}

	/**
	 * Getter for the second cluster of the pair
	 * 
	 * @return the second cluster of the pair
	 */
	public Cluster getSecond()
	{
		return cluster2;
	}
}
